Subject: Reducing screen flicker in simple animation.
Date: Mon, 21 Feb 1994 13:17:13 GMT
Organization: Computing Laboratory, U of Newcastle upon Tyne, UK NE1 7RU.
I'll make the apology first for this being a newbie question, but I'm in a bit of a time fix so I need some help. (and where better to look?)
A little background:
I'm writing a simple algorithm animator for the Mac (and other platforms .....) I'm just moving simple rectangles round the screen so there's no need for complex animation stuff. Based on a book by Mark Watson ( Portable GUI development in C++) which IMO ain't bad, but is a bit buggy, I've got redraw etc to work OK. The problem is the screen flicker, mainly due, I guess, to constantly erasing and redrawing the object which are moving.
My solution:
I propose to draw to an off screen grafPort then use copyBits to move the image from offScreen.portBits to screen.portBits.
The question:
Very simple.... is this right?? Is the reduction in flicker worth the bother or shall I just spend my precious (no not precious, just very limited!) time on something else? Is there a better way? I get the impression qd provides some explicit support for this kind of thing.....
Thanks for your help, I may even understand all this one day!!!
Peter
(P.A.Brooks-Johnson@newcastle.ac.uk)
+++++++++++++++++++++++++++
>From Michael Burks <mb1i+@andrew.cmu.edu>
Date: Mon, 21 Feb 1994 11:07:53 -0500
Organization: Fifth yr. senior, Math/Computer Science, Carnegie Mellon, Pittsburgh, PA
Excerpts from netnews.comp.sys.mac.programmer: 21-Feb-94 Reducing screen
flicker in .. by P.A. Brooks-Johnson@newc
> <How do I move rectangles around the screen without flicker deleted>
> My solution:
> I propose to draw to an off screen grafPort then use copyBits to move
the image
> from offScreen.portBits to screen.portBits.
>
> The question:
> Very simple.... is this right?? Is the reduction in flicker worth the
bother or
> shall I just spend my precious (no not precious, just very limited!)
time on som
> ething else? Is there a better way? I get the impression qd provides
some explic
> it support for this kind of thing.....
>
> Thanks for your help, I may even understand all this one day!!!
>
What you propose will work. I would call it psuedo-double bufferring.
It's a common thing. Whether you want to do it is a very subjective
question.
There are lots of other solutions. If it's just rectangles, you could
easily keep track of what pixels have changed yourself (this extends to
polygons), and only update them. You could also use color cycling
(animating colors).
Blaine.
+++++++++++++++++++++++++++
>From Sander C. Temme <temme@phys.uva.nl>
Date: 22 Feb 94 14:00:18 +0100
Organization: University of Amsterdam
In article <CLKswq.B8y@newcastle.ac.uk> P.A. Brooks-Johnson,
P.A.Brooks-Johnson@newcastle.ac.uk writes:
>The question:
>Very simple.... is this right?? Is the reduction in flicker worth
the bother or
>shall I just spend my precious (no not precious, just very
limited!) time on
>something else? Is there a better way? I get the impression qd
provides some
>explicit support for this kind of thing.....
The easiest way to do this is documented in the acclaimed book 'How
to Write Macintosh Software' by Scott Knaster as 'Smooth Animation
for the Rest of Us':
You can synchronize your drawing with the vertical retrace (i.e.
when the electron beam moves from lower right corner to upper left
corner of the screen) so you change the video RAM when no drawing is
going on. When the Mac hits vertical retrace, it generates an
interrupt. One of the things this interrupt does is increase the
TickCount global Variable. So, what the rest of us do to get smooth
animation is let our program sit in a tight loop waiting for
TickCount to change, and when it does, draw like heck.
Only, this method dates from way back when multiple screens and
CQuickDraw weren't an issue. You'll have to see whether it still
works. When it did (when I toyed around with simple animation on a
Plus), it gave nice results for all its simplicity.
>
>Thanks for your help, I may even understand all this one day!!!
(-: (-:
Sander
Sander C. Temme, University of Amsterdam, Holland temme@phys.uva.nl